package com.jye.rseven.user.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jye.rseven.Constants.MyConstants;
import com.jye.rseven.domain.JsonResult;
import com.jye.rseven.domain.Task;
import com.jye.rseven.domain.TyPtCode;
import com.jye.rseven.service.TyPtCodeService;
import com.jye.rseven.service.TzPtCodeService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/TyPtCode")
@Api(tags=" 团员API")
public class TyPtCodeController {

    @Reference
    TyPtCodeService tyPtCodeService;

    @Reference
    TzPtCodeService tzPtCodeService;

    @PostMapping("/addTy")
    @ApiOperation(value="添加团员信息", notes="根据团员实体添加实体", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name = "TyPtCode",
                    value = "团员实体类", required = true,
                    dataType = "com.jye.rseven.user.domain.TyPtCode"),
    })
    public JsonResult addTy(TyPtCode tyPtCode) {
        JsonResult jsonResult = new JsonResult();
        int i = tyPtCodeService.addTy(tyPtCode);
        if (i == 1) {
            jsonResult.setData("添加成功!");

        } else {
            jsonResult.setData("添加失败!");
            jsonResult.setCode("500");
        }
        return jsonResult;
    }

    @GetMapping("/findPtByUId")
    @ApiOperation(value="查找我的拼团", notes="根据查找我的任务", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name = "uId",
                    value = "用户id", required = true,
                    dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "skip",
                    value = "跳过多少条", required = true,
                    dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "limit",
                    value = "限制多少条", required = true,
                    dataType = "Integer"),
    })
    public JsonResult findPtByUId(int uId, int skip, int limit){
        JsonResult jsonResult = new JsonResult();
        List<TyPtCode> list = tyPtCodeService.findPtByUId(uId,skip,limit);
        if (list.size()!=0 ){
            jsonResult.setData(list);
        }else{
            jsonResult.setCode("500");
            jsonResult.setMsg("未查询到记录，查询失败");
        }
        return jsonResult;
    }

    @GetMapping("/findPtById")
    @ApiOperation(value="查找单个拼团", notes="根据查找我的任务", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name = "Id",
                    value = "用户id", required = true,
                    dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "skip",
                    value = "跳过多少条", required = true,
                    dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "limit",
                    value = "限制多少条", required = true,
                    dataType = "Integer"),
    })
    public JsonResult findPtById(int Id){
        JsonResult jsonResult = new JsonResult();
        TyPtCode tyPtCode = tyPtCodeService.findPtById(Id);
        if (tyPtCode !=null ){
            jsonResult.setData(tyPtCode);
        }else{
            jsonResult.setCode("500");
            jsonResult.setMsg("未查询到记录，查询失败");
        }
        return jsonResult;
    }



}
